﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductManagement.ProductBomVMs
{
    public partial class ProductBomListVM : BasePagedListVM<ProductBom_View, ProductBomSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductBom_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductBom_View>>{

                 this.MakeGridHeader(x => x.ProductBom_OpCode).SetTitle(@Localizer["Page.所属工序"].Value),
                this.MakeGridHeader(x => x.ProductBom_Product).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductBom_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductBom_Material).SetTitle(@Localizer["Page.物料"].Value),
                this.MakeGridHeader(x => x.ProductBom_MaterialName).SetTitle(@Localizer["Page.物料名称"].Value),
                this.MakeGridHeader(x => x.ProductBom_Qty).SetTitle(@Localizer["Page.需求数量"].Value),
                this.MakeGridHeader(x => x.ProductBom_Unit).SetTitle(@Localizer["Page.单位"].Value),
                this.MakeGridHeader(x => x.ProductBom_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProductBom_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProductBom_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProductBom_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductBom_View> GetSearchQuery()
        {
            var query = DC.Set<ProductBom>()
                
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckEqual(Searcher.Qty, x=>x.Qty)
                .CheckContain(Searcher.Unit, x=>x.Unit)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProductBom_View
                {
				    ID = x.ID,
                    
                    ProductBom_Product = x.Product.Name,
                    ProductBom_ProductName = x.ProductName,
                    ProductBom_OpCode=x.OpCode,
                    ProductBom_Material = x.Material.Name,
                    ProductBom_MaterialName = x.MaterialName,
                    ProductBom_Qty = x.Qty,
                    ProductBom_Unit = x.Unit,
                    ProductBom_CreateTime = x.CreateTime,
                    ProductBom_UpdateTime = x.UpdateTime,
                    ProductBom_CreateBy = x.CreateBy,
                    ProductBom_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductBom_View: ProductBom
    {
        public string ProductBom_OpCode { get; set; }

        public string ProductBom_Product { get; set; }
        public string ProductBom_ProductName { get; set; }
        public string ProductBom_Material { get; set; }
        public string ProductBom_MaterialName { get; set; }
        public decimal? ProductBom_Qty { get; set; }
        public string ProductBom_Unit { get; set; }
        public DateTime? ProductBom_CreateTime { get; set; }
        public DateTime? ProductBom_UpdateTime { get; set; }
        public string ProductBom_CreateBy { get; set; }
        public string ProductBom_UpdateBy { get; set; }

    }

}